package com.iyao_app.adapter;

import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.iyao_app.R;
import com.iyao_app.entry.SceneUser;
import com.iyao_app.util.ResourcesUtils;

import java.util.List;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/11/21.
 */

public class LatelyPersonsCenterAdapter extends BaseQuickAdapter<SceneUser, BaseViewHolder> {


    public LatelyPersonsCenterAdapter(@Nullable List<SceneUser> data) {
        super(R.layout.item_qian_dao_person, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, SceneUser item) {
        SimpleDraweeView mSdvPhoto = helper.getView(R.id.sdv_photo);
        TextView mTvName = helper.getView(R.id.tv_name);

        TextView mTvGuanzhu = helper.getView(R.id.tv_guanzhu);

        helper.itemView.setLayoutParams(new RecyclerView.LayoutParams((int) ResourcesUtils.getDimension(R.dimen.x590), (int) ResourcesUtils.getDimension(R.dimen.x748)));
        try {
            Uri uri = Uri.parse(item.avatarUrl);
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                    .setResizeOptions(new ResizeOptions((int) ResourcesUtils.getDimension(R.dimen.x590), (int) ResourcesUtils.getDimension(R.dimen.x748)))
                    .build();
            PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setOldController(mSdvPhoto.getController())
                    .setImageRequest(request)
                    .build();
            mSdvPhoto.setController(controller);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mTvName.setText(item.nickName);
        switch (item.friendShip) {
            case -1:
                mTvGuanzhu.setText("关注");
                mTvGuanzhu.setVisibility(View.VISIBLE);
                break;
            case 1:
                mTvGuanzhu.setVisibility(View.VISIBLE);
                mTvGuanzhu.setText("已关注");
                break;
            case 2:
                mTvGuanzhu.setText("关注");
                mTvGuanzhu.setVisibility(View.VISIBLE);
                break;
            case 4:
                mTvGuanzhu.setText("聊天");
                mTvGuanzhu.setVisibility(View.VISIBLE);
                break;
            case 5:
                mTvGuanzhu.setText("关注");
                mTvGuanzhu.setVisibility(View.VISIBLE);
                break;
            default:
                mTvGuanzhu.setVisibility(View.GONE);
                break;
        }
        helper.addOnClickListener(R.id.tv_guanzhu);
    }

}
